package com.lxd.sunso.product.service.impl;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxd.sunso.product.dao.AreaDao;
import com.lxd.sunso.product.entity.AreaEntity;
import com.lxd.sunso.product.service.AreaService;


@Service("areaService")
public class AreaServiceImpl extends ServiceImpl<AreaDao, AreaEntity> implements AreaService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AreaEntity> page = this.page(
                new Query<AreaEntity>().getPage(params),
                new QueryWrapper<AreaEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<AreaEntity> queryList(Map<String, Object> params) {
        List<AreaEntity> list = this.list(new QueryWrapper<AreaEntity>().orderByAsc("area"));
        return list;
    }

    @Override
    public void saveArea(AreaEntity area) {
        String areaName = area.getArea();
        this.remove(new QueryWrapper<AreaEntity>().eq("area", areaName));
        this.save(area);
    }
}